package com.qidian.by.cms.controller;
import com.alibaba.fastjson2.JSON;
import com.qidian.by.cms.service.IContentService;
import com.qidian.by.pojo.Content;
import com.qidian.by.util.pojo.EsResult;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小可怎么都睡不够
 * @since 2024-05-06
 */
@RestController
@RequestMapping("/content")
public class ContentController {


    @Autowired
    private IContentService contentService;

    @GetMapping("/list")
    public EsResult getContentList(@RequestParam(defaultValue = "")String text1,@RequestParam(defaultValue = "")String text2,@RequestParam(defaultValue = "-1")Long catId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit) {
        Content content = new Content();
        content.setText1(text1);
        content.setText2(text2);
        if(catId!=-1){
            content.setCatId(catId);
        }
        return contentService.queryDetailInfo(content, limit, page);
    }

    @PutMapping("/save")
    public EsResult save(@RequestBody Content content) {
        return contentService.saveAndReverse(content);
    }

    @PostMapping("/update")
    public EsResult updateContentInfo(@RequestBody Content content){
        return contentService.updateContent(content);
    }


    @GetMapping("/listByCatMark")
    public EsResult getListByCatMark(@RequestParam String catMark, @RequestParam(defaultValue = "-1") Integer count) {

        return contentService.getContentListByCatMark(catMark, count);
    }
}
